package com.accompany.fragment.my.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import com.accompany.R;
import com.accompany.base.BaseActivity;
import com.accompany.utils.FullScreenUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class RecruitAccompanyingMemberActivity extends BaseActivity {
    @BindView(R.id.base_title)
    TextView mTitleMsg;
    @Override
    public int getLayoutId() {
        return R.layout.activity_recruit_accompanying_member;
    }
    @Override
    public void initLayoutView() {
        mTitleMsg.setText("陪诊员招募");
        FullScreenUtils.getInstance().fullScreen(RecruitAccompanyingMemberActivity.this, true);
    }

    @OnClick({R.id.base_back, R.id.shenqing_msg, R.id.kefu_msg})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finishWitchAnimation();
                break;
            case R.id.shenqing_msg:
                openActivityWitchAnimation(ZhaomuPeiZhenYuanActivity.class);
                break;
            case R.id.kefu_msg:
                // 检查是否获得了权限
                if (ContextCompat.checkSelfPermission(RecruitAccompanyingMemberActivity.this,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    // 若没有获得授权，申请授权
                    if (ActivityCompat.shouldShowRequestPermissionRationale(RecruitAccompanyingMemberActivity.this,
                            Manifest.permission.CALL_PHONE)) {
                        // 如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.
                        //  如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.
                        // 如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
                        // 弹窗需要解释为何需要该权限，再次请求授权
                        // 帮跳转到该应用的设置界面，让用户手动授权
                        Intent call = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", RecruitAccompanyingMemberActivity.this.getPackageName(), null);
                        call.setData(uri);
                        startActivity(call);
                    } else {
                        // 不需要解释为何需要该权限，直接请求授权
                        ActivityCompat.requestPermissions(RecruitAccompanyingMemberActivity.this,
                                new String[]{Manifest.permission.CALL_PHONE},
                                0);
                    }
                } else {
                    // 已经获得授权，可以打电话
                    // 通过intent跳转到拨打电话的界面
                    Intent intent1 = new Intent();
                    intent1.setAction(Intent.ACTION_CALL);
                    Uri phoneNum = Uri.parse("tel:" + "0931-8797777");
                    intent1.setData(phoneNum);
                    startActivity(intent1);
                }
                break;
        }
    }
}